function getSign(address) {
  var timestamp = new Date() * 1;
  var source = "web";
  // var random = Math.random();
  var token ="";
      if(!sessionStorage.getItem("token")){
        token = "";
      }else{
        token = sessionStorage.getItem("token");
      }
  // var token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ7XCJhZG1pbkZsYWdcIjoxLFwiY29tcGFueUlkXCI6MTAwMDE0MSxcImNvbXBhbnlOYW1lXCI6XCI2MTDotYTkuqdcIixcImNvbXBhbnlUeXBlXCI6MixcImlkXCI6MjcsXCJuYW1lXCI6XCLlsI_mmI5cIixcInJvbGVDb2RlXCI6XCJST0xFX0FTU0VUXCJ9IiwiZXhwIjoxNTYwNDM4Mjk3fQ.T35FuNmdRQfsCVB2aW3LnaSs9cgLg2XCCZAxiK5f2I4";
  var index = address.indexOf("/api");
  var url = address.slice(index);
  var sign = hex_md5(timestamp + source + token + url);
  
  var headers = {
    timestamp: timestamp,
    source: source,
    token: token,
    sign: sign,
    "Content-Type": "application/json"
  };
  return headers;

}

var service = new Object();
service.host_url = "";
service.request = function(address, method, options, back) {
  var headers = getSign(address);
  // console.log(headers);
  // var headers = {debug:'1'};

  if (method == "get") {
    axios
      .get(service.host_url + address, {
        params: options,
        headers: headers
      })
      .then(function(res) {
        if (res.data.code == 407) {
          window.location.href = "./../login/login.html";
        } else {
          back(res);
        }
      });
  } else if (method == "post") {
    axios
      .post(service.host_url + address, options, {
        headers: headers
      })
      .then(function(res) {
        if (res.data.code == 407) {
          window.location.href = "./../login/login.html";
        } else {
          back(res);
        }
      });
  }
};

// 登录
var login_server = new Object();
// login_server.login = function(params, back) {
//   service.request(
//     "/videosurvey/scheduleCase/getAllSeat",
//     "get",
//     params,
//     function(data) {
//       back(data);
//     }
//   );
// };

/*登陆注册********************************************** */
//登录
login_server.login = function(data, back) {
  service.request("/zhixuan/api/v1/user/login", "post", data, function(data) {
    back(data);
  });
};
//注册
login_server.register = function(data, back) {
  service.request("/zhixuan/api/v1/user/register", "post", data, function(
    data
  ) {
    back(data);
  });
};
//获取验证码
login_server.getVerifyCode = function(data, back) {
  service.request("/zhixuan/api/v1/user/getVerifyCode", "post", data, function(
    data
  ) {
    back(data);
  });
};
//忘记密码
login_server.forgetPassword = function(data, back) {
  service.request("/zhixuan/api/v1/user/forgetPassword", "post", data, function(
    data
  ) {
    back(data);
  });
};

// 房源
var house_server = new Object();
/*
 **楼盘接口
 */
// 4.01获取楼盘图片列表
house_server.getBuildImg = function(query, back) {
  service.request(
    "/zhixuan/api/v1/building/getBuildingOutDoorPic",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
// 获取全部待租空间
house_server.getAllWait = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/attention/allwaithouse/json",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
// 获取楼盘基本信息
house_server.getHouseInfo = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/house/gethouseinfo",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
// 获取楼盘周边推荐
house_server.getRecommend = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/house/recommend",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};

/**公共接口******************************************************************************************/
//获取月浏览量
house_server.getCountVisit = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/countVisit",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//获取月浏览量(多)
house_server.getCountVisits = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/countVisits",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//添加浏览记录
house_server.addVisit = function(query, back) {
  service.request("/zhixuan/api/v1/user/opt/addVisit", "post", query, function(
    data
  ) {
    back(data.data);
  });
};
//获取关注人数
house_server.getAttentionTypeNum = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/attentionTypeNum",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//获取关注人数(多
house_server.getAttentionTypeNums = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/attentionTypeNums",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
// 获取收藏人数
house_server.getHouseCollectionNum = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/houseCollectionNum",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//获取收藏人数(多)
house_server.getHouseCollectionNums = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/houseCollectionNums",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//经纪人/管理公司 区县房源数量
house_server.getStatTownHouseNum = function(query, back) {
  service.request(
    "/zhixuan/api/v1/building/statTownHouseNum",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};


//根据城市id获取区县
house_server.getCommonCityItems = function(params, back) {
  service.request(
    "/zhixuan/api/v1/common/getCommonCityItems",
    "get",
    params,
    function(data) {
      back(data.data);
    }
  );
};
//获取热门品牌
house_server.hotBrand = function(params, back) {
  service.request(
    "/zhixuan/api/v1/filterOrSort/hotBrand",
    "get",
    params,
    function(data) {
      back(data.data);
    }
  );
};
//获取热搜便签
house_server.getHotSearch = function(query, back) {
  service.request(
    "/zhixuan/api/v1/filterOrSort/hotSearch",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//获取热搜便签
house_server.getAllRecommendHouse = function(query, back) {
  service.request(
    "/zhixuan/api/v1/company/apiAllRecommendHouse",
    "get",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//写字楼园区按楼盘搜索
house_server.searchBuildingPage = function(query, back) {
  service.request(
    "/zhixuan/api/v1/building/searchBuildingPage",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//联合办公按社区搜索
house_server.searchCommunityPage = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/searchCommunityPage",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//联合办公搜索-按品牌
house_server.searchByBrandPage = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/searchBrandPage",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//资产管理公司搜索
house_server.searchByHousePage = function(query, back) {
  service.request(
    "/zhixuan/api/v1/building/searchBuildingHousePage",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//推荐楼盘
house_server.recommendBuilding = function(params, back) {
  service.request(
    "/zhixuan/api/v1/filterOrSort/recommendBuilding",
    "get",
    params,
    function(data) {
      back(data.data);
    }
  );
};
//房源周边推荐
house_server.recommendedHouseNearby = function(query, back) {
  service.request(
    "/zhixuan/api/v1/building/recommendedHouseNearby",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//楼盘周边推荐
house_server.recommendedBuildingNearby = function(query, back) {
  service.request(
    "/api/v1/building/recommendedBuildingNearby",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};

/**联合办公品牌及社区******************************************************************************************/
//联合办公品牌基本信息
house_server.getBrandBaseInfo = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/getBrandBaseInfo",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//联合办公品牌页社区印象
house_server.getCommunityImpress = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/getCommunityImpress",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//联合办公品牌热推空间
house_server.getBrandHotPush = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/getBrandHotPush",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//联合办公品牌会员见解
house_server.getBrandOption = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/getBrandOption",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//联合办公社区基本信息
house_server.getCommunityBaseInfo = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/getCommunityBaseInfo",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
house_server.getCommunityList = function(query, back){
  service.request(
    "/zhixuan/api/v1/brand/getBrandDetail",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
}
//联合办公社区房源
house_server.getHouseList = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/getHouseList",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//社区附加服务及服务设施列表
house_server.getCommunityPic = function(query, back) {
  service.request(
    "/zhixuan/api/v1/community/getCommunityPic",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//推荐社区
house_server.getRecommendCommunity = function(params, back) {
  service.request(
    "/zhixuan/api/v1/filterOrSort/recommendCommunity",
    "get",
    params,
    function(data) {
      back(data.data);
    }
  );
};

/**资产管理公司******************************************************************************************/
//资产管理公司全部房源
house_server.getAllHouse = function(query, back) {
  service.request("/zhixuan/api/v1/company/allHouse", "post", query, function(
    data
  ) {
    back(data.data);
  });
};
//资产管理公司推荐房源
house_server.getRecommendHouse = function(query, back) {
  service.request(
    "/zhixuan/api/v1/company/recommendHouse",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//资产管理公司基本信息
house_server.getCompanyInfo = function(query, back) {
  service.request(
    "/zhixuan/api/v1/company/companyInfo",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
/**代理公司经纪人店铺******************************************************************************************/
//经纪人店铺基本信息
house_server.getBrokerInfo = function(query, back) {
  service.request("/zhixuan/api/v1/broker/brokerInfo", "post", query, function(
    data
  ) {
    back(data.data);
  });
};
//经纪人全部房源
house_server.getBrokerAllHouse = function(query, back) {
  service.request("/zhixuan/api/v1/broker/allHouse", "post", query, function(
    data
  ) {
    back(data.data);
  });
};
//经纪人店铺推荐房源
house_server.getBrokerRecommendHouse = function(query, back) {
  service.request(
    "/zhixuan/api/v1/broker/recommendHouse",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//委托找房录入
house_server.getEntrustCreate = function(query, back) {
  service.request(
    "/zhixuan/api/v1/buildingApply/create",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//获取经纪人电话咨询次数
// house_server.getBrokerPhoneNum = function(query, back) {
//   service.request(
//     "/zhixuan/api/",
//     "post",
//     query,
//     function(data) {
//       back(data.data);
//     }
//   );
// };
//点击电话记录咨询次数
// house_server.addBrokerPhoneNum = function(query, back) {
//   service.request(
//     "/zhixuan/api/",
//     "post",
//     query,
//     function(data) {
//       back(data.data);
//     }
//   );
// };
/**入住平台******************************************************************************************/
//开发商录入
house_server.getDevelopersCreate = function(query, back) {
  service.request(
    "/zhixuan/api/v1/buildingApply/create",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//个人业主录入
house_server.getPersonalCreate = function(query, back) {
  service.request(
    "/zhixuan/api/v1/buildingApply/create",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
//代理公司录入
house_server.getCompanyCreate = function(query, back) {
  service.request(
    "/zhixuan/api/v1/buildingApply/create",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};

/**搜索列表*****************************************************************************************/

house_server.getSearchBuildingHousePage = function(query, back) {
  service.request(
    "/zhixuan/api/v1/building/searchBuildingHousePage",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
/**搜索列表*****************************************************************************************/
var other_server = new Object();

other_server.addAttention = function(query, back) {
  service.request(
    "/zhixuan/api/v1/user/opt/addAttention",
    "post",
    query,
    function(data) {
      back(data.data);
    }
  );
};
